//
//  LeftViewController.m
//  Project_2_weibo
//
//  Created by 林林 on 16/6/18.
//  Copyright © 2016年 lhn. All rights reserved.
//

#import "LeftViewController.h"
#import "ThemeManager.h"
#import "MMExampleDrawerVisualStateManager.h"

@interface LeftViewController () <UITableViewDelegate, UITableViewDataSource>
{
    UITableView *_tbView;
    NSArray *_arr;
    NSInteger _index;
}

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    //设置背景图片
    ThemeImageView *bgImageView = [[ThemeImageView alloc] initWithFrame:self.view.bounds];
    bgImageView.imageName = @"mask_bg.jpg";
    [self.view insertSubview:bgImageView atIndex:0];
    self.title = @"配置";
    
    //初始化
    _index = 3;
    _arr = @[@"无",
             @"滑动",
             @"滑动&缩放",
             @"3D旋转",
             @"视差滑动"];
    
    [self createTableView];
    
    //监听通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChanged) name:kThemeChangedNotificationName object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)themeChanged {
    [_tbView reloadData];
}

- (void)createTableView {
    
    _tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth / 2, kScreenHeight - 64) style:UITableViewStylePlain];
    _tbView.delegate = self;
    _tbView.dataSource = self;
    _tbView.backgroundColor = [UIColor clearColor];
    //去掉下面多余的线
    _tbView.tableFooterView = [[UIView alloc] init];
    
    [self.view addSubview:_tbView];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.textLabel.text = _arr[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:13];
    cell.textLabel.textColor = [[ThemeManager sharedManager] themeColorWithColorName:@"Timeline_Content_color"];
    cell.imageView.image = [[ThemeManager sharedManager] themeImageWithImageName:@"avatar_default.png"];
    cell.backgroundColor = [UIColor clearColor];
    
    //去掉选中效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == _index) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    _index = indexPath.row;
    [_tbView reloadData];
    
    MMExampleDrawerVisualStateManager *manager = [MMExampleDrawerVisualStateManager sharedManager];
    manager.leftDrawerAnimationType = indexPath.row;
    manager.rightDrawerAnimationType = indexPath.row;

    [manager drawerVisualStateBlockForDrawerSide:MMDrawerSideLeft];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
